#include <cstdio>
#include <string>
#include <iostream>
#include <cctype>
#include <algorithm>
#include <cmath>

bool MyCompare(char a, char b) {
	int lowerA = std::tolower(a);
	int lowerB = std::tolower(b);
	if (lowerA != lowerB) {
		return lowerA < lowerB;
	}
	return a < b;
}


/**
 * 时间复杂度：O((mn)log(mn))
 * 空间复杂度：O(mn)
 * 
 * 信件
 * @return
 */
int main() {
	int n, m;

	scanf("%d%d", &n, &m);

	std::string allChars;
	allChars.reserve(n * m);
	for (int i = 0; i < n; i++) {
		std::string line;
		std::cin >> line;
		allChars += line;
	}


	std::sort(allChars.begin(), allChars.end(), MyCompare);

	int k = allChars.size();
	int middle = (int)std::sqrt(k);
	int p = 1, q = k;
	for (int i = middle; i >= 1; i--) {
		if (k % i == 0) {
			p = i;
			q = k / i;
			break;
		}
	}

	for (int i = 0; i < p; i++) {
		printf("%s\n", allChars.substr(i * q, q).c_str());
	}

	return 0;
}